import java.util.Arrays;
import java.util.Scanner;

/**
 * @author vivi
 * @description
 * @date 2024/5/21
 */
public class demo2 {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] arr = new int[n][2];

        for (int i = 0; i < n; i++) {
            arr[i][0] = scanner.nextInt();
            arr[i][1] = scanner.nextInt();
        }

        Arrays.sort(arr, (a, b) ->
        {
            return a[0] <= b[0] ? -1 : 1;
        });

        int ret = 1;
        int tmp = arr[0][1];

        for (int i = 1; i < n; i++) {
            if (arr[i][0] < tmp) {
                //有重复的数组
                tmp = Math.min(tmp, arr[i][1]);
            }else {
                //没有重复的数组
                ret ++;
                tmp = arr[i][1];
            }
        }
        System.out.println(ret);
    }
}
